package com.gec.anan.driver.controller;

import com.gec.anan.common.login.AnanLogin;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.util.AuthContextHolder;
import com.gec.anan.driver.service.LocationService;
import com.gec.anan.model.form.map.OrderServiceLocationForm;
import com.gec.anan.model.form.map.UpdateDriverLocationForm;
import com.gec.anan.model.form.map.UpdateOrderLocationForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "位置API接口管理")
@RestController
@RequestMapping(value="/location")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationController {
	@Autowired
    private LocationService locationService;

    @Operation(summary = "司机开始接单，更新司机在geo的信息")
    @AnanLogin
    @PostMapping("/updateDriverLocation")
    public Result<Boolean> updateDriverLocation(@RequestBody UpdateDriverLocationForm updateDriverLocationForm){
        Long driverId = AuthContextHolder.getUserId();
        updateDriverLocationForm.setDriverId(driverId);
        return Result.ok(locationService.updateDriverLocation(updateDriverLocationForm));
    }

    @Operation(summary = "司机停止接单，删除掉geo中司机的信息")
    @AnanLogin
    @PostMapping("/removeDriverLocation/{driverId}")
    public Result<Boolean> removeDriverLocation(@PathVariable("driverId")Long driverId){
//        Long driverId = AuthContextHolder.getUserId();
        return Result.ok(locationService.removeDriverLocation(driverId));
    }

    @Operation(summary = "司机赶往代驾起始点：更新订单位置到Redis缓存")
    @AnanLogin
    @PostMapping("/updateOrderLocationToCache")
    public Result<Boolean>updateOrderLocationToCache(@RequestBody UpdateOrderLocationForm updateOrderLocationForm) {
        return Result.ok(locationService.updateOrderLocationToCache(updateOrderLocationForm));
    }


    @Operation(summary = "开始代驾服务：保存代驾服务订单位置")
    @PostMapping("/saveOrderServiceLocation")
    public Result<Boolean>saveOrderServiceLocation(@RequestBody List<OrderServiceLocationForm> orderServiceLocationFormList){
        return Result.ok(locationService.saveOrderServiceLocation(orderServiceLocationFormList));
    }
}

